package br.utfpr.edu.managedBean;

import java.io.File;

import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import br.utfpr.edu.business.NegocioException;
import br.utfpr.edu.utility.Zip;


public class RelatorioBaseFrm extends FormularioBase  {

	private static final long serialVersionUID = 8542786266724209076L;

	public void gerarArquivoFasta(String caminho)throws NegocioException{
		File arquivo = new File(caminho);
		try {
			//4. Enviar o txt para o browser do cliente.
			byte[]rel = Zip.arquivoParaBytes(arquivo);
			HttpServletResponse response = getResponse();
	        response.setContentType("application/fasta");
	        response.setHeader("Content-Disposition","attachment;filename="+arquivo.getName());
	        ServletOutputStream out = response.getOutputStream();
	        out.write(rel, 0, rel.length);
	        out.flush();
	        out.close();	        
	        FacesContext.getCurrentInstance().responseComplete();
		} catch (Exception e) {
			throw new NegocioException(e+"");
		}finally{
			arquivo.delete();
		}
	}
}
